package moon.core;

/**
 * Name. Each object has an unique name.
 * 
 * @author <a href="mailto:rmartico@ubu.es">Ra&uacute;l Marticorena</a>
 * @since JavaMoon-2.1.0
 */
@SuppressWarnings("serial")
public abstract class Name extends ObjectMoon implements Comparable<Name>{

	/**
	 * Name.
	 */
	private String name;
	
	/**
	 * Constructor.
	 * 
	 * @param name name
	 */
	public Name(String name){
		this.name = name;
	}
	
	public String toString(){
		return this.name;
	}
	
	/**
	 * Concats the name with the current name.
	 * 
	 * @param name name to concat
	 * @return concat name 
	 */
	public abstract Name concat(Name name);

	/**
	 * Concats the name with the current name.
	 * 
	 * @param name name to concat
	 * @return concat name 
	 */
	public abstract Name concat(String name);
	
	/**
	 * Compares current name.
	 * 
	 * @param name name
	 * @return 0 if are equals, different value in other cases
	 */
	public int compareTo(Name name){
		return this.toString().compareTo(name.toString());
	}
	
	/**
	 * {@inheritDoc}.
	 * 
	 * @param object object
	 * @return {@inheritDoc}
	 */
	@Override
	public boolean equals(Object object){
		if (!(object instanceof Name) || object == null){
			throw new IllegalArgumentException("Type value not allowed.");
		}
		return (((Name) object).compareTo(this)==0);
	}
	
	/**
	 * Returns the hashcode.
	 * 
	 * @return hashcode
	 */
	@Override
	public int hashCode(){
		if (name!=null){		
			return this.name.hashCode();
		}
		else{
			return -1;
		}
	}
} // Name
